import router from '@/router'
import usetoken from './stores/token'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
// 路由前置守卫
// 设置白名单
const whrite = ['/login','/404']
router.beforeEach((to, from, next) => {
    // nprogress.start() // 开启进度条
    const {token} = usetoken()
    if(token){
        if(to.path === '/login'){
            next('/')

        }else{
            next()
        }
    }else{
        if(whrite.includes(to.path)){
            next()
        }else{
            next('/login')
          
        }

    }
 
})
router.afterEach(() => {
    // to and from are both route objects.
    //关闭进度条
    nprogress.done()


})()

